var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("GameEm"),
    s = t("BaseRoadCatDataCom"),
    c = t("CarAnimal"),
    p = t("CarStatusCom"),
    l = cc._decorator,
    d = l.ccclass,
    u =
        (l.property,
        l.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.carAnimal = null;
                e.carStatus = null;
                e.cookMul = 1;
                e.isWanMei = !1;
                e.offDisIndex = 250;
                e.checkIndex = r.Cat0Index.continueWait;
                e.isPlayAnimalSleep = !1;
                return e;
            }
            e.prototype.setBaseData = function (e, o, a, i, n) {
                t.prototype.setBaseData.call(this, e, o, a, i, n);
                this.updateSpeeds();
                this.checkIndex = r.Cat0Index.continueWait;
                this.cookMul = 1;
                if (!this.carAnimal) {
                    var s = this.node.getComponent(c.default);
                    this.carAnimal = s;
                }
                this.carAnimal && this.carAnimal.initPos(this.node.position);
                if (!this.carStatus) {
                    s = this.node.getComponent(p.default);
                    this.carStatus = s;
                }
                this.checkTask();
            };
            e.prototype.setCarColor = function (t) {
                if (!this.carStatus) {
                    var e = this.node.getComponent(p.default);
                    this.carStatus = e;
                    this.carStatus.catSkinColor.color = t;
                }
            };
            e.prototype.getMoveCs = function () {
                return this.moveCs;
            };
            e.prototype.resetCsMove = function (t) {
                if (this.checkIndex == r.Cat0Index.checkNextMove && t != this.moveCs) {
                    this.moveCs = t;
                    for (var e = [], o = 0; o < this.movePath.length; o++) e.push(this.movePath[o]);
                    this.setPath(e);
                    this.startMoveNode(null, this.checkWaitMove.bind(this));
                    this.pathIndexOff = this.getPathDisToIndex(e, this.moveCs * this.offDisIndex);
                }
            };
            e.prototype.checkWaitMove = function () {
                this.pathIndex++;
                if (
                    this.movePath &&
                    this.movePath[this.pathIndex] &&
                    this.pathIndex < this.movePath.length - this.pathIndexOff
                )
                    this.startMoveNode(null, this.checkWaitMove.bind(this));
                else {
                    0 == this.moveCs && this.checkTask();
                    EvCat.emit(EvCat.updateCheckView);
                }
            };
            e.prototype.isNextCarMove = function () {
                return this.checkIndex == r.Cat0Index.checkNextMove;
            };
            e.prototype.getCarWayAren = function () {
                return this.curMoveWayAren;
            };
            e.prototype.checkDoTask = function (t) {
                this.checkIndex = t.task;
                switch (t.task) {
                    case r.Cat0Index.checkNextMove:
                        this.moveCs <= 0 ? this.checkTask() : (CacheDataManager.canCheckAllMinCs = !0);
                        break;
                    case r.Cat0Index.carMoveWay:
                        this.curMoveWayAren = t.toId + "";
                        TaskGameEvent.emit(TaskGameEvent.roadCatLeave, t.index, t.cs, "0");
                    case r.Cat0Index.moveWalk:
                        this.pathIndex = 0;
                        this.moveCs = t.cs || 0;
                        this.pathIndexOff = this.getPathDisToIndex(t.path, this.moveCs * this.offDisIndex);
                        this.setPath(t.path);
                        this.startMoveNode(t.startToPos, this.moveOver.bind(this));
                        this.playWalkAnimal();
                        break;
                    case r.Cat0Index.moveGetFoodData:
                        this.pathIndex = 0;
                        this.moveCs = t.cs || 0;
                        this.pathIndexOff = this.getPathDisToIndex(t.path, this.moveCs * this.offDisIndex);
                        this.setPath(t.path);
                        this.startMoveNode(t.startToPos, this.moveGetFoodOver.bind(this));
                        this.playWalkAnimal();
                        break;
                    case r.Cat0Index.waitFood:
                        this.playWaitAnimal();
                        TaskGameEvent.emit(TaskGameEvent.openCarGetNpcFood, this.kind, this.id, this.moveAren, t);
                        break;
                    case r.Cat0Index.waitMove:
                        this.playWaitAnimal();
                        this.checkNextTask = 1;
                        TaskGameEvent.emit(TaskGameEvent.taskKind, this.kind, this.id, this.moveAren, t);
                        break;
                    case r.Cat0Index.removeFoodKind:
                        TaskGameEvent.emit(TaskGameEvent.removeTabFood, t);
                        this.checkTask();
                        break;
                    case r.Cat0Index.moveOverFood:
                        this.carStatus && this.carStatus.unStatus();
                        this.pathIndex = 0;
                        this.curMoveWayAren = "-1";
                        this.setPath(t.path);
                        this.startMoveNode(t.startToPos, this.moveOver.bind(this));
                        this.playWalkAnimal();
                        TaskGameEvent.emit(TaskGameEvent.roadCatLeave, t.index, t.cs, "1");
                        EvCat.emit(EvCat.recCatCall, this.kind, "1");
                        break;
                    case r.Cat0Index.continueWait:
                        this.playSeelpWait();
                        TaskGameEvent.emit(TaskGameEvent.taskKind, this.kind, this.id, this.moveAren, t);
                        break;
                    case r.Cat0Index.moveToDlg:
                        this.playWalkAnimal();
                        t.startToPos && (this.movePath = []);
                        this.startMoveNode(t.startToPos, this.moveOver.bind(this));
                        break;
                    case r.Cat0Index.dlg:
                        this.playWaitAnimal();
                        this.carStatus && this.carStatus.viewWait(t.waitTime, t, this.dlgOver.bind(this));
                        break;
                    case r.Cat0Index.cooking:
                        this.playWaitAnimal();
                        this.carStatus && this.carStatus.viewWait(t.waitTime, t, this.cookingOver.bind(this));
                        break;
                    case r.Cat0Index.downFood:
                        this.carStatus && this.carStatus.unStatus();
                        TaskGameEvent.emit(
                            TaskGameEvent.downFood,
                            this.cookMul,
                            t.index,
                            t.toTab2Index,
                            t.toId2,
                            t.toId,
                            t.count,
                            t.toAren,
                            this.isWanMei,
                            ""
                        );
                        this.moveOver();
                }
            };
            e.prototype.updateFoodStatus = function (t, e) {
                if (this.checkEvent && t == this.id && this.carStatus) {
                    this.carStatus.wantFood(e) || this.checkNextTask++;
                    if (this.checkNextTask) {
                        this.checkNextTask = 0;
                        this.checkTask();
                    }
                }
            };
            e.prototype.cookingOver = function (t) {
                TaskGameEvent.emit(TaskGameEvent.setCookStatus, t.toId2, !1);
                this.cookMul = 1;
                this.isWanMei = !1;
                if (CacheDataManager.isPerfectRateAdd(this.id + "", this.kindIndex + "")) {
                    this.cookMul = CacheDataManager.addWanMeiTime;
                    this.isWanMei = !0;
                }
                if (this.carStatus) {
                    var e = t.toId + "";
                    this.carStatus.viewFoodTip(
                        e,
                        CacheDataManager.getMulProfit(e, CacheDataManager.getFoodLevel(e), this.cookMul)
                    );
                }
                this.moveOver();
            };
            e.prototype.dlgOver = function (t) {
                this.carStatus && this.carStatus.unStatus();
                this.moveOver();
                TaskGameEvent.emit(TaskGameEvent.addCookTask, t.index, t.toId);
            };
            e.prototype.addEvWaitFood = function () {};
            e.prototype.moveOver = function () {
                if (this.pathIndex >= this.movePath.length - 1 - this.pathIndexOff) this.checkTask();
                else {
                    this.pathIndex++;
                    this.startMoveNode(null, this.moveOver.bind(this));
                }
            };
            e.prototype.moveGetFoodOver = function () {
                this.moveOver();
            };
            e.prototype.checkTask = function () {
                if (this.taskList.length > 0 && this.taskIndex < this.taskList.length) {
                    var t = this.taskList[this.taskIndex];
                    this.taskIndex++;
                    this.checkDoTask(t);
                } else {
                    this.clearData();
                    this.recNode();
                }
            };
            e.prototype.playWalkAnimal = function () {
                this.isPlayAnimalSleep = !1;
                this.carAnimal;
            };
            e.prototype.playWaitAnimal = function () {
                this.isPlayAnimalSleep = !1;
                this.carAnimal;
            };
            e.prototype.playSeelpWait = function () {
                this.isPlayAnimalSleep = !0;
            };
            e.prototype.updateCheckAnimal = function () {
                if (this.isPlayAnimalSleep) {
                    this.isPlayAnimalSleep = !1;
                    this.carAnimal;
                }
            };
            return n([d], e);
        })(s.default));
o.default = u;
